document.write('<script type="text/javascript" src="../static/js/back/utils.js"></script>');
document.write('<script type="text/javascript" src="../static/js/back/ajax.js"></script>');
var _url_ = '../table/addTablesInfo.do';
var _url_edit = '../table/updateTablesInfo.do';
var _url_list = '../trans/getShopTransList';
var _url_id = '../table/getTablesById';
var _map = {};
var _pageNum = 1;
var _type ;
var spid="";
  $(function(){
	   spid = getCookie("shop_id");
	  _type = getUrlParam("type");
	  console.log(_type);
	  if(_type === "add"){
		 // getTypeListAdd();
		  _showData = {};
		  $("#shopId").val(spid);
	  }else if(_type === "edit"){
		  showEditData();
		  _url_ = _url_edit;
	  }else{
//		  getTypeList();
		  getZHInfo();
		  var uid = getCookie("uid");
		  _map["shopUserId"] = uid;
		  getSysSet();
		  getList();
	  }
  });
$(function(){
	  $("body").on("click",".mypage span",function(){
		  _pageNum = $(this).attr("data-status");
		  getList();
	  });
	  $(".tix-record").click(function(){
		  showRecord();
		  $(".x-body.one").hide();
		  $(".x-body.two").show();
	  })
});
  function getList(){
	  _map['shopId'] = spid;
	  _map['pageNum'] = _pageNum;
	  _map['isusetleft'] = 1;
	  _ajax_get_token(_url_list,_map,function(res){
		  console.log(res);
		  console.log(res.returnObject);
		  if(!res.returnObject||res.returnObject.length<=0 ){
			  $(".layui-table tbody").html("");
			  $(".no-more-data").show();
			  $(".mypage").hide();
			  return;
		  }else{
			  $(".mypage").show();
			  $(".no-more-data").hide();
		  }
		  var html = "";
		  var stat = "" , statHtml = "";
		  showPageInfo(res.returnObject);
		  $(".x-right").text("共有数据："+res.returnObject.total +" 条");
		  var html,stat,statStr,typeStr,sendTypeStr;
		  $.each(res.returnObject.list,function(i,v,arr){
			  console.log(v);
			  
			  if(v.tranType == 1){
				  if(v.type == 1 ){
					  typeStr = "订单退款";
				  }else{
					  typeStr = "订单收入";
				  }
			  }else if(v.tranType == 2){
				  if(v.type == 1 ){
					  typeStr = "余额提现";
				  }else{
					  typeStr = "余额提现退款";
				  }
			  }else{
				  return
				  ;
			  }
			  
			  if(v.status == 1){
				  statStr = "通过";
			  }else if (v.status == 2) {
				  statStr = "拒绝";
			  }else {
				  if(v.type == 2 && v.status == 3){
					  statStr = "待结算";
				  }else{
					  statStr = '待审核';
				  }
			  }
			  html+=' <tr><td>'
// 	             +' <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id="'+v.id+'" ><i class="layui-icon">&#xe605;</i></div>'
// 	             +' </td>                                                                                                                  '
// 	             +' <td>'
 	             +(i+1)+'</td>                                                                                                             '
 	             +' <td>'+v.createTime
 	             +'</td>                                                                                           '
// 	             +' <td align="center"><a target="_blank" href="'+v.adUrl+'"><img  src="'+v.adPic+'" height=50 widht=50 ></a></td>                                                                                                      '
// 	             +' <td>'+v.adUrl+'</td>                                                                                                      '
 	             +' <td>'+typeStr+'</td>                                                                                                      '
 	             +' <td >'+(v.type ==1 ? "- " : "+  ") +(v.amount / 100).toFixed(2)+'</td>'
 	             +' <td >'+statStr+'</td>'
 	             +' </tr>';
		  });
		  $(".one .layui-table tbody").html(html);
	  });
  }
  function getSysSet(){
	  _ajax_post_token('../trans/getShopTranSet',{},function(res){
		  	console.log(res);
		  	$(".platPhone").text(res.returnObject.platPhone);
		  	$(".minpr").val(res.returnObject.minAmount);
	  });
	  
  }
  function getZHInfo(){
	  var mm = {};
	  if( getCookie("shop_id") != 0 ){
		  mm['shopId'] = getCookie("shop_id");
		  mm['userType'] = 2;
	  }else{
		  mm['id'] =getCookie('uid');
	  }
	  _ajax_post_token('../crus/getUserById',mm,function(res){
		  console.log(res);
		  if(res.resultCode == 1000){
			 var dd = res.returnObject;
			 $(".layui-col-xs4").eq(0).find("p").eq(1).find("span").text(dd.userName);
			 $(".layui-col-xs4").eq(0).find("p").eq(2).find("span").text(dd.userWxName);
			 
			 $(".layui-col-xs4").eq(1).find("p").eq(1).text("¥"+(dd.amount/100).toFixed(2));
			 
			 $(".layui-col-xs4").eq(2).find("p").eq(1).text("¥"+(dd.amountLeft/100).toFixed(2));
		  }
	  });
  }
  function moneycash(){
   	  var ht = ' <div style="margin:10px" align="center" > <input type="text" name="username" id="mone"  placeholder="请输入提现金额" autocomplete="off" class="layui-input"><br><button class="layui-btn layui-btn" onclick="cashok(this)">确定</button> <button class="layui-btn layui-btn-normal" onclick="cancel()">取消</button> </div>';
   	  layer.open({
   			type:1,
   			area: '300px',
   			content:ht
   		})
  }
function cancel(){
	 $('.layui-layer-close').click();
	 $("#mone").val("");
}
function cashok(obj){
	
	var uid = getCookie("uid");
	console.log(spid);
	var mm = $("#mone").val();
	if(!$.isNumeric(mm)){
		 layer.msg('请输入正确的数字',{icon:5,time:2000});
		 return;
	}
	var mt = (mm * 100).toFixed(0);
	if(mt==0){
		layer.msg('请输入大于0的数字',{icon:5,time:2000});
		return;
	}
	var min = $(".minpr").val();
	console.log(min+"-"+mt);
	if(min > mt){
		layer.msg('最低提现金额为:'+(min/100).toFixed(0)+'元,请重新输入',{icon:5,time:2000});
		return;
	}
	disAddBtn(obj);
	_ajax_post_token('../trans/addShopTranInfo.do',{shopUserId:uid,shopId:spid,amount:mt},function(res){
		console.log(res);
		if(res.resultCode == 1009){
			layer.msg('可提现金额不足,请重新输入',{icon:5,time:2000});
			console.log(obj);
			celDisAddBtn(obj);
			return;
		}else if(res.resultCode == 1000){
			layer.msg('操作成功',{icon:6,time:2000});
			cancel();
			window.location.href= document.location;
		}else if(res.resultCode == 1011){
			layer.msg(res.returnObject,{icon:5,time:2000});
			celDisAddBtn(obj);
			return;
		}
		celDisAddBtn(obj);
	});
}
function showRecord(){
	 _map['shopId'] = spid;
	  _map['pageNum'] = _pageNum;
	  _map['tranType'] = 2;
	  _ajax_get_token(_url_list,_map,function(res){
		  console.log(res);
		  console.log(res.returnObject);
		  if(!res.returnObject||res.returnObject.length<=0 ){
			  $(".layui-table tbody").html("");
			  $(".no-more-data").show();
			  $(".mypage").hide();
			  return;
		  }else{
			  $(".mypage").show();
			  $(".no-more-data").hide();
		  }
		  var html = "";
		  var stat = "" , statHtml = "";
		  showPageInfo(res.returnObject);
		  $(".x-right").text("共有数据："+res.returnObject.total +" 条");
		  var html,stat,statStr,typeStr,sendTypeStr;
		  $.each(res.returnObject.list,function(i,v,arr){
			  console.log(v);
			  if(v.tranType == 1){
				  typeStr = "外卖订单";
			  }else if(v.tranType == 2){
				  typeStr = "余额提现";
			  }
			  
			  if(v.type == 1){
				  typeStr+="退换";
			  }
			  if(v.status == 1){
				  statStr = "提现成功";
			  }else if (v.status == 2) {
				  statStr = "提现失败";
			  }else {
				  statStr = '审核中';
			  }
			  html+=' <tr><td>'
//	             +' <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id="'+v.id+'" ><i class="layui-icon">&#xe605;</i></div>'
//	             +' </td>                                                                                                                  '
//	             +' <td>'
	             +(i+1)+'</td>                                                                                                             '
	             +' <td>'+v.serialNumber 
	             +'</td>                                                                                           '
//	             +' <td align="center"><a target="_blank" href="'+v.adUrl+'"><img  src="'+v.adPic+'" height=50 widht=50 ></a></td>                                                                                                      '
//	             +' <td>'+v.adUrl+'</td>                                                                                                      '
	             +' <td >'+(v.amount / 100).toFixed(2)+'</td>'
	             +' <td>'+v.createTime+'</td>                                                                                                      '
	             +' <td >'+statStr+'</td>'
	             +' </tr>';
		  });
		  $(".two .layui-table tbody").html(html);
	  });
}